//
//  GLTransferInsetsObject.m
//  GLLibDemo
//
//  Created by huang long on 2018/4/18.
//  Copyright © 2018年 历山大亚. All rights reserved.
//

#import "GLTransferInsetsObject.h"

@interface GLTransferInsetsObject()

//@property (nonatomic, assign)<#type#> <#name#>;

@end

@implementation GLTransferInsetsObject

- (instancetype)initWithSize:(CGSize)size
{
    self = [super init];
    if (self) {
        _contentSize = size;
        _insetsType = GLTransferInsetsTypeSize;
        _alpha = 0.5;
    }
    return self;
}

- (instancetype)initWithScale:(CGSize)scale
{
    self = [super init];
    if (self) {
        _contentScale = scale;
        _insetsType = GLTransferInsetsTypeScale;
        _alpha = 0.5;
    }
    return self;
}

- (instancetype)initWithOffset:(CGPoint)offset
{
    self = [super init];
    if (self) {
        _contentOffset = offset;
        _insetsType = GLTransferInsetsTypeOffset;
        _alpha = 0.5;
    }
    return self;
}

- (CGRect)rectFromOriginFrame:(CGRect)frame{
    CGRect rect = frame;
    switch (self.insetsType) {
        case GLTransferInsetsTypeSize:
        {
            CGFloat offsetX = frame.size.width - self.contentSize.width;
            CGFloat offsetY = frame.size.height - self.contentSize.height;
            rect = CGRectInset(frame, offsetX * 0.5, offsetY * 0.5);
            break;
        }case GLTransferInsetsTypeScale:
        {
            CGFloat offsetX = frame.size.width - self.contentScale.width * frame.size.width;
            CGFloat offsetY = frame.size.height - self.contentScale.height * frame.size.height;
            rect = CGRectInset(frame, offsetX * 0.5, offsetY * 0.5);
            break;
        }case GLTransferInsetsTypeOffset:
        {
            rect = CGRectInset(frame, self.contentOffset.x, self.contentOffset.y);
            break;
        }
        default:
            break;
    }
    return rect;
}

@end
